package com.china08.yxyapi.util;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

public class EsQuestionUpdateUtil {

    private static final Logger LOGGER = LoggerFactory.getLogger(EsQuestionUpdateUtil.class);

    private static final String ES_YXY_QUESTION_SINGLE_QUEUE = "es-yxy-question-single-queue";

    private static final String ES_YXY_QUESTION_BATCH_QUEUE = "es-yxy-question-batch-queue";

    public static void updateEsQuestion(String questionId) {
        LOGGER.info("发送的试题Id：" + questionId);
        try {
            RabbitTemplate template = SpringContextUtil.getBean(RabbitTemplate.class);
            if (StringUtils.isNotBlank(questionId)) {
                template.convertAndSend(ES_YXY_QUESTION_SINGLE_QUEUE, questionId.trim());
            }
        } catch (Exception e) {
            LOGGER.error("发送试题id异常", e);
        }
        LOGGER.info("发送的试题Id结束");
    }

    public static void updateEsQuestionList(List<String> questionId) {
        for (String string : questionId) {
            LOGGER.info("发送的多个试题Id：" + string);
        }
        try {
            RabbitTemplate template = SpringContextUtil.getBean(RabbitTemplate.class);
            if (questionId != null && questionId.size() > 0) {
                template.convertAndSend(ES_YXY_QUESTION_BATCH_QUEUE, questionId);
            }
        } catch (Exception e) {
            LOGGER.error("发送试题id异常", e);
        }
        LOGGER.info("发送的试题Id结束");
    }

}
